package com.qfmrk.controller;

import com.qfmrk.entity.User;
import com.qfmrk.service.UserService;
import com.qfmrk.util.R;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * --- 永无霸哥 ---
 *
 * @author M.rk
 * @date 2024/11/23 11:29
 * @desc
 */
@RestController
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    private Logger logger = LogManager.getLogger(UserController.class);

    //    /user/UserLoginByPassword
    @PostMapping("/user/UserLoginByPassword")
    public R UserLoginByPassword(@RequestBody User user) {
        logger.debug("数据在这里—————》{}" + user);
        User login = userService.UserLoginByPassword(user);

        if (login != null) {
            return R.ok(login);
        }

        return R.fail();
    }

    //    /user/AddUser
    @PostMapping("/user/AddUser")
    public R AddUser(@RequestBody User user) {
        logger.debug("数据在这里—————》{}" + user);
        int i = userService.AddUser(user);

        if (i > 0) {
            return R.ok();
        }

        return R.fail();
    }

}
